package stack;

import java.util.Stack;

public class min_stack {
    Stack<Integer> stack = new Stack<>();
    Stack<Integer> minstack = new Stack<>();


    public void push(int node) {
        stack.push(node);
        if (minstack.isEmpty() || minstack.peek() > node) {
            minstack.push(node);
        } else {
            minstack.push(minstack.peek());
        }
    }

    public void pop() {

        stack.pop();

        minstack.pop();

    }

    public int top() {
        if (stack.isEmpty()) {
            return -1;
        }
        return stack.peek();
    }

    public int min() {
        return minstack.peek();
    }
}
